using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace JlPay.Sdk.Models.Trans.Dto
{
    /// <summary>
    /// 商品明细DTO
    /// @author liaochangyi
    /// @since 2025-01-25
    /// </summary>
    public class GoodsDetailDto
    {
        /// <summary>
        /// 商品编码
        /// </summary>
        [JsonPropertyName("goods_id")]
        public string? GoodsId { get; set; }

        /// <summary>
        /// 微信侧商品编码
        /// </summary>
        [JsonPropertyName("wxpay_goods_id")]
        public string? WxpayGoodsId { get; set; }

        /// <summary>
        /// 商品名称
        /// </summary>
        [JsonPropertyName("goods_name")]
        public string? GoodsName { get; set; }

        /// <summary>
        /// 商品数量
        /// </summary>
        [JsonPropertyName("quantity")]
        public string? Quantity { get; set; }

        /// <summary>
        /// 商品单价
        /// </summary>
        [JsonPropertyName("price")]
        public string? Price { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        public GoodsDetailDto()
        {
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="goodsDict">商品明细字典</param>
        public GoodsDetailDto(Dictionary<string, object>? goodsDict)
        {
            if (goodsDict != null)
            {
                GoodsId = goodsDict.TryGetValue("goods_id", out var goodsId) ? goodsId?.ToString() : null;
                WxpayGoodsId = goodsDict.TryGetValue("wxpay_goods_id", out var wxpayGoodsId) ? wxpayGoodsId?.ToString() : null;
                GoodsName = goodsDict.TryGetValue("goods_name", out var goodsName) ? goodsName?.ToString() : null;
                Quantity = goodsDict.TryGetValue("quantity", out var quantity) ? quantity?.ToString() : null;
                Price = goodsDict.TryGetValue("price", out var price) ? price?.ToString() : null;
            }
        }

        /// <summary>
        /// 转换为字典格式
        /// </summary>
        /// <returns>字典数据</returns>
        public Dictionary<string, object?> ToDictionary()
        {
            return new Dictionary<string, object?>
            {
                ["goods_id"] = GoodsId,
                ["wxpay_goods_id"] = WxpayGoodsId,
                ["goods_name"] = GoodsName,
                ["quantity"] = Quantity,
                ["price"] = Price
            };
        }
    }
} 